package org.nowcoder.leetcode.BSearch;

/**
 * Title  : 367. Valid Perfect Square
 * Source : https://leetcode.cn/problems/valid-perfect-square/description/
 * Author : XrazYang
 * Date   : 2023-10-30
 */

public class LeetCode_367 {
    public boolean isPerfectSquare(int num) {
        int left = 1, right = num < 2 ? num : num / 2;
        while (left <= right) {
            int mid = left + ((right - left) >> 1);
            if ((long) mid * mid > num) {
                right = mid - 1;
            } else if ((long) mid * mid < num) {
                left = mid + 1;
            } else {
                return true;
            }
        }
        return false;
    }
}
